﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1017OOEX
{
    class Vehicle : IMoveable
    {
        public string aName;
        public int X;
        public int Y;
        public Vehicle(int _x, int _y)
        {
            X = _x; Y = _y;
            aName = "汽车";
        }
        public string Say()
        {
            return "滴滴滴";
        }
        //虚函数，本类族使用虚函数实现多态
        public virtual string SayHello(string _fName)
        {
            return "Hi " + _fName + "你好！" + "我是" + aName;
        }
        //实现接口
        public void Move(SquareClass _square)
        {
            int dx = _square.rnd.Next(-1, 2);//产生的随机数不包括上界值
            int dy = _square.rnd.Next(-1, 2);
            //汽车每次移动两个栅格
            if (X + dx * 2 < _square.Width && X + dx * 2 >= 0) X = X + dx;
            if (Y + dy * 2 < _square.height && Y + dy * 2 >= 0) Y = Y + dy;
        }
    }
}
